<template>
	<view>
		<view class="listbox" v-for="(item,index) in info.goods">
			<view class="leftbox">
				<image :src="item.url"></image>
			</view>
			<view class="rightbox">
				<view class="name">{{item.goods_name}}</view>
				<view class="spec_name">{{item.spec_name}}</view>
				<view class="goods_num">X{{item.goods_num}}</view>
				<view class="goods_price">{{item.goods_price}}</view>
			</view>
		</view>
		<view class="selectbox" v-if="logistics.length">
			<input placeholder="请输入快递单号" v-model="ship_num" />
		</view>
		<view class="selectbox" v-if="logistics.length">
			<picker :range="logistics" range-key="expressCompanyName" @change="changelogistics">
				<view style="display: flex;align-items: center;justify-content: flex-end;">
					{{afterSaleExpressCompanyName==null?'请选择':afterSaleExpressCompanyName}}
					<image src="../../static/right@2.png"></image>
				</view>
			</picker>
		</view>
		<view style="height: 120rpx;"></view>
		<view class="navbut">
			<view @click="sumbit()">提交</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				info: {},
				logistics:[],
				afterSaleExpressCompanyName:null,
				afterSaleExpressCompanyCode:null,
				ship_num:'',
				id:'',
				fding:true,
			}
		},
		onLoad(option) {
			this.info = JSON.parse(decodeURIComponent(option.info))
			console.log(this.info, 'info')
			if(this.info.orderItem[0].afterSaleOrderId){
				this.getlogistics()
			}
		},
		methods: {
			getlogistics(){
				this.$http({
					url:'api/Xiaoxiang/getAftersaleLogistics',
					data:{
						afterSaleOrderId:this.info.orderItem[0].afterSaleOrderId||'',
					}
				}).then(res=>{
					this.logistics = res.data
				})
			},
			changelogistics(e){
				this.afterSaleExpressCompanyCode = this.logistics[e.detail.value].expressCompanyCode
				this.afterSaleExpressCompanyName = this.logistics[e.detail.value].expressCompanyName
				console.log(e,this.afterSaleExpressCompanyCode,this.afterSaleExpressCompanyName)
			},
			sumbit(){
				if(this.info.store_id==32&&this.afterSaleExpressCompanyName==null){
					uni.showToast({
						title:'请选择要寄回的快递公司',
						icon:'none'
					})
					return
				}
				if(!this.ship_num){
					uni.showToast({
						title:'请先输入快递单号',
						icon:'none'
					})
					return
				}
				if(this.fding){
					this.fding = false
					this.$http({
						url:'/api/Wechat/refShipNum',
						data:{
							ref_id:this.info.id,
							ship_num:this.ship_num,
							afterSaleExpressCompanyCode:this.afterSaleExpressCompanyCode,
							afterSaleExpressCompanyName:this.afterSaleExpressCompanyName,
						}
					}).then(res=>{
						uni.showToast({
							title:res.msg,
							icon:'none'
						})
						setTimeout(()=>{
							this.fding = true
							uni.navigateBack({
								delta:1
							})
						})
					})
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.listbox {
		width: 690rpx;
		padding: 30rpx;
		background-color: #FFF;
		display: flex;
		align-items: center;
		font-size: 26rpx;
		color: #666;

		.leftbox {
			width: 160rpx;
			text-align: center;

			image {
				width: 120rpx;
				height: 120rpx;
			}
		}

		.rightbox {
			width: 530rpx;
			font-family: SourceHanSansCN-Medium-, SourceHanSansCN-Medium;
			font-weight: normal;
			.name {
				font-size: 28rpx;
				color: #222222;
				-webkit-line-clamp: 2;
				display: -webkit-box;
				-webkit-box-orient: vertical;
				overflow: hidden;
				text-overflow: ellipsis;
			}
			.spec_name{
				-webkit-line-clamp: 1;
				display: -webkit-box;
				-webkit-box-orient: vertical;
				overflow: hidden;
				text-overflow: ellipsis;
				color: #666666;
				height: 45rpx;
				line-height: 45rpx;
			}
			.goods_num{
				color: #666666;
				height: 45rpx;
				line-height: 45rpx;
			}
			.goods_price{
				font-size: 28rpx;
				font-family: SourceHanSansCN-Medium-, SourceHanSansCN-Medium;
				font-weight: normal;
				color: #222222;
				height: 45rpx;
				line-height: 45rpx;
			}
		}
	}
	.selectbox{
		width: 690rpx;
		padding: 0 30rpx;
		background-color: #FFF;
		font-size: 28rpx;
		color: #222222;
		display: flex;
		justify-content: flex-end;
		align-items: center;
		height: 100rpx;
		margin-top: 20rpx;
		>picker{
			width: 660rpx;
			text-align: right;
			image{
				width: 18rpx;
				height: 34rpx;
				margin-left: 30rpx;
			}
		}
		>input{
			width: 660rpx;
			text-align: right;
		}
	}
	.navbut{
		width: 750rpx;
		height: 110rpx;
		background-color: #FFF;
		position: fixed;
		bottom: 0;
		z-index: 9;
		>view{
			width: 690rpx;
			border-radius: 36rpx;
			margin: 15rpx auto;
			height: 80rpx;
			line-height: 80rpx;
			text-align: center;
			color: #FFF;
			background-color: #F94D29;
		}
	}
</style>